<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function* something() {
        try {
            var nextVal = 0;
            while (true) {
                if (nextVal == undefined) {
                    nextVal = 1;
                } else {
                    nextVal = (3 * nextVal) + 6;
                }
                console.log(nextVal)
                yield nextVal;
            }

        }
        finally {
            console.log("cleaning up");
            yield 3;
            yield 4;        // 使用了return等的行为（包括在for of中的break等）会跳进finally中，但是还是可以继续迭代
        }
    }

    var it = something();
    it.next();
    it.next();
    console.log(it.return());        // value: 3, done: false           若是finally之中没有yield，则return之后next就没有用了
    console.log(it.next());          // {value: 4, done: false}
</script>

</html>